/**
 * Object Common()
 * @constructor
 * @class Common
 */
function Common() {}

Common.prototype = {
        
    ctx : "",
    
    /*
     * Judgements
     */

    /**
     * 判断参数是不是string类型
     * 空字符串返回的布尔值是false
     * @param s
     * @return boolean
     */
    isString : function (s) {
        return s && "string" === typeof s;
    },
    
    isNotString : function (s) {
        return !this.isString(s);
    },
    
    /**
     * 判断参数是不是number类型
     * @param n
     * @return boolean
     */
    isNumber : function (n) {
        return "number" === typeof n;
    },
    
    isNotNumber : function (n) {
        return !this.isNumber(n);
    },
    
    /**
     * 判断参数是不是object类型
     * <code>null</code>的类型也是object，所有必须判断
     * @param o
     * @return boolean
     */
    isObject : function (o) {
        return o && "object" === typeof o;
    },
    
    isNotObject : function (o) {
        return !this.isObject;
    },
    
    /**
     * 判断参数是不是function类型
     * @param f
     * @return boolean
     */
    isFunction : function (f) {
        return "function" === typeof f;
    },
    
    isNotFunction : function (f) {
        return !this.isFunction(f);
    },
    
    /**
     * 判断当前浏览器是不是 Microsoft Internet Explorer
     * @return boolean
     */
    isIE : function () {
        return "Microsoft Internet Explorer" === navigator.appName;
    },
    
    isNotIE : function () {
        return !this.isIE();
    },
    
    /**
     * 判断当前浏览器是不是 Firefox
     * @return boolean
     */
    isFF : function () {
        return "Netscape" === navigator.appName;
    },
    
    isNotFF : function () {
        return !this.isFF();        
    },
    
    getBrowserType : function () {
        var i = -1;
        switch (navigator.appName) {
            case "Microsoft Internet Explorer" :
                i = Browser.IE;
                break;
                
            case "Netscape" :
                i = Browser.FF;
                break;
        }
        return i;
    },
    
    $E : function (id, w) {
        if (this.isNotString(id)) {
            window.alert("参数id不是字符串：$E(id)");
            return null;
        }
        var d = (w && w.document) ? w.document : document;
        return d.getElementById(id);
    },
    
    
    /*
     * Usage:
     * _$E({id: '', name: '', context: o});
     */
    /**
     * 
     * @param params
     * @return
     */
    _$E : function (params) {
        /*
        params.id
        params.name
        */
        var c = params.context || document;
    },
    
    /*
     * Position-related
     */
    
    moveTo : function (e, p) {
        if (this.isNotObject(e) || !p || this.isNotNumber(p.x) || this.isNotNumber(p.y)) {
            return;
        }
        e.style.left = this.addUnit(p.x);
        e.style.top = this.addUnit(p.y);
    },
    
    moveToX : function (e, x, callback) {
        if (this.isNotObject(e) || this.isNotNumber(x)) {
            return;
        }
        
        var instance = this;
        var s = e.style;
        var l = s.left ? parseInt(s.left) : this.getLeft(e);
        var b = l > x;
        var v = b ? -10 : 10;
        var a = b ? 1 : -1;
        
        var interval = window.setInterval(function () {
            l = s.left ? parseInt(s.left) : instance.getLeft(e);
            if (l !== x) {
                if (Math.abs(l - x) < 55 && Math.abs(v) > 1) {
                    v += a;
                }
                s.left = instance.addUnit((l + v > x) === b ? l + v : x);
            } else {
                window.clearInterval(interval);
                interval = null;
                
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, 1);
    },
    
    moveToY : function (e, y, callback) {
        if (this.isNotObject(e) || this.isNotNumber(y)) {
            return;
        }
        
        var instance = this;
        var s = e.style;
        var t = s.top ? parseInt(s.top) : this.getTop(e);
        var b = t > y;
        var v = b ? -10 : 10;
        var a = b ? 1 : -1;
        
        var interval = window.setInterval(function () {
            t = s.top ? parseInt(s.top) : instance.getTop(e);
            if (t !== y) {
                if (Math.abs(t - y) < 55 && Math.abs(v) > 1) {
                    v += a;
                }
                s.top = instance.addUnit((t + v > y) === b ? t + v : y);
            } else {
                window.clearInterval(interval);
                interval = null;
                
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, 1);
    },
    
    moveBy : function (e, offset) {
        if (this.isNotObject(e) || !offset || this.isNotNumber(offset.x) || this.isNotNumber(offset.y)) {
            return;
        }
        var l = e.style.left ? parseInt(e.style.left) : 0;
        var t = e.style.top ? parseInt(e.style.top) : 0;
        e.style.left = this.addUnit(l + offset.x);
        e.style.top = this.addUnit(t + offset.y);
    },
    
    getLeft : function (e) {
        var left = e.offsetLeft;
        if (e.offsetParent) {
            left += this.getLeft(e.offsetParent);
        }
        return left;
    },
    
    getTop : function (e) {
        var top = e.offsetTop;
        if (e.offsetParent) {
            top += this.getTop(e.offsetParent);
        }
        return top;
    },
    
    center : function (e) {
        if (this.isNotObject(e)) {
            return;
        }
    
        var d = e.ownerDocument;
    
        var decw = d.documentElement.clientWidth;
        var dech = d.documentElement.clientHeight;
        var desl = d.documentElement.scrollLeft;
        var dest = d.documentElement.scrollTop;
        
        var w = e.style.width ? parseInt(e.style.width) : e.clientWidth;
        var h = e.style.height ? parseInt(e.style.height) : e.clientHeight;
        
        e.style.left = this.addUnit(Math.floor((w > decw ? 0 : (decw - w) / 2)) + desl);
        e.style.top = this.addUnit(Math.floor((h > dech ? 0 : (dech - h) / 2)) + dest);
    },
    
    dnd : function (e) {
        if (this.isNotIE()) {
            return;
        }
        
        // 如果element无效
        if (this.isNotObject(e)) {
            return;
        }
        
        var moveable = false;
        var downX = 0;
        var downY = 0;
        
        e.onmousedown = function () {
            
            // 如果不是鼠标左键, 则不触发
            if (1 != window.event.button) {
                return;
            }
            
            // 获取焦点
            e.setCapture();
            e.style.cursor = "move";
            
            var left = e.offsetLeft;
            var top = e.offsetTop;
            
            // 保存鼠标按下时的坐标
            downX = window.event.x - left;
            downY = window.event.y - top;
            
            // 打开拖放开关
            moveable = true;
        };
        
        e.onmouseup = function () {
            
            // 释放焦点
            e.releaseCapture();
            e.style.cursor = "default";
            
            // 关闭拖放开关
            moveable = false;
        };
        
        e.onmousemove = function () {
            
            // 如果拖放开关打开, 则可以拖放
            if (moveable) {
                e.style.top = (window.event.y - downY) + "px";
                e.style.left = (window.event.x - downX) + "px";
            }
        };
    },
    
    shakeWindow : function () {
        for (var i = 0; i < 30; i++) {
            window.top.moveBy(0, 10);
            window.top.moveBy(10, 0);
            window.top.moveBy(0, -10);
            window.top.moveBy(-10, 0);
        }
    },
    
    shakeElement : function (e) {
        var instance = this;
        var offset = 5;
        var flag = -1;
        var timeout = null;
        
        var f  = function () {
            if (-1 === flag) {
                instance.moveBy(e, {x: 0, y: offset});
                window.setTimeout(function () {
                    instance.moveBy(e, {x: offset, y: 0});
                }, 20);
            } else {
                instance.moveBy(e, {x: 0, y: -offset});
                window.setTimeout(function () {
                    instance.moveBy(e, {x: -offset, y: 0});
                }, 20);
            }
            flag = -flag;
            timeout = window.setTimeout(function () {
                f();
            }, 40);
        };
        f();
        window.setTimeout(function () {
            window.clearTimeout(timeout);
            timeout = null;
        }, 1000);
    },
    
    /*
     * Size-related
     */
    
    zoomIn : function (e, callback) {
        
        // 如果传入的元素无效, 什么都不做, 直接回返
        if (this.isNotIE() || this.isNotObject(e)) {
            return;
        }
        
        var instance  = this;
        var v = 0.1;// 速度(velocity)
        
        e.style.zoom = "0.01";
        
        // 如果元素被隐藏, 将它显示
        if ("none" === e.style.display) {
            e.style.display = "";
        }
        
        var interval = window.setInterval(function () {
            
            // 元素的缩放倍数
            var zoom = parseFloat(e.style.zoom);
            
            // 如果缩放倍数小于1, 继续放大
            if (1 > zoom) {
                v += 0.1;
                e.style.zoom = (zoom + v > 1 ? 1 : zoom + v).toString();
            
            // 已经达到100%
            } else {
                
                // 清除interval
                window.clearInterval(interval);
                interval = null;
                
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, 50);
    },
    
    zoomOut : function (e, callback) {
        
        // 如果传入的元素无效, 什么都不做, 直接回返
        if (this.isNotIE() || this.isNotObject(e)) {
            return;
        }
        
        var instance = this;
        var v = 0.1;// 速度(velocity)
        
        var interval = window.setInterval(function () {
            
            // 元素的缩放倍数
            var zoom = e.style.zoom ? parseFloat(e.style.zoom) : 1.0;
            
            // 如果缩放倍数大于0.1, 继续缩小
            if (0.01 < zoom) {
                v += 0.1;
                e.style.zoom = (zoom - v < 0.01 ? 0.01 : zoom - v).toString();
            
            // 已经到达最小, 隐藏元素
            } else {
                e.style.display = "none";
                
                // 清除interval
                window.clearInterval(interval);
                interval = null;
                
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, 50);
    },
    
    /**
     * 逐渐放大高度
     * @param e HTML DOM 对象
     */
    zoomInHeight : function (e, callback) {
        if (this.isNotObject(e)) {
            return;
        }
        
        var v = 10,// 速度(velocity)
            h = e.offsetHeight;
        e.style.height = "1px";
        
        var interval = window.setInterval(function () {
            
            // 
            var h2 = parseInt(e.style.height);
            
            // 
            if (h2 < h) {
                if ((h - h2) < 55 && v > 1) {
                    v -= 1;
                }
                e.style.height = this.addUnit((h2 + v > h ? h : h2 + v).toString());
            
            // 
            } else {
                
                // 清除interval
                window.clearInterval(interval);
                interval = null;
                
                if (this.isFunction(callback)) {
                    callback();
                }
            }
        }, 1);
    },

    /**
     * 逐渐放大宽度
     * @param e HTML DOM 对象
     */
    zoomInWidth : function (e, callback) {
        if (this.isNotObject(e)) {
            return;
        }
        
        var v = 10,// 速度(velocity)
            w = e.offsetWidth;
        e.style.width = "1px";
        
        var interval = window.setInterval(function () {
            
            // 
            var w2 = parseInt(e.style.width);
            
            // 
            if (w2 < w) {
                if ((w - w2) < 55 && v > 1) {
                    v -= 1;
                }
                e.style.width = this.addUnit((w2 + v > w ? w : w2 + v).toString());
            
            // 
            } else {
                
                // 清除interval
                window.clearInterval(interval);
                interval = null;
                
                if (this.isFunction(callback)) {
                    callback();
                }
            }
        }, 1);
    },

    /*
     * Window-related
     */
    
    openWin : function (url, width, height, isMax) {
        var aw = screen.availWidth;
        var ah = screen.availHeight;
        var left = Math.floor((aw - width) / 2);
        var top = Math.floor((ah - height) / 2);
        var title = "";
        if (isMax) {
            left = 0;
            top = 0;
            width = aw;
            height = ah;
        }
        var fs = 'fullscreen=yes';
        var w = window.open(url, title, fs);
        window.opener = null;
        window.close();
    },
    
    /*
channelmode=yes|no|1|0 是否使用剧院模式显示窗口。默认为 no。 
directories=yes|no|1|0 是否添加目录按钮。默认为 yes。 
fullscreen=yes|no|1|0 是否使用全屏模式显示浏览器。默认是 no。处于全屏模式的窗口必须同时处于剧院模式。 
height=pixels 窗口文档显示区的高度。以像素计。 
left=pixels 窗口的 x 坐标。以像素计。 
location=yes|no|1|0 是否显示地址字段。默认是 yes。 
menubar=yes|no|1|0 是否显示菜单栏。默认是 yes。 
resizable=yes|no|1|0 窗口是否可调节尺寸。默认是 yes。 
scrollbars=yes|no|1|0 是否显示滚动条。默认是 yes。 
status=yes|no|1|0 是否添加状态栏。默认是 yes。 
titlebar=yes|no|1|0 是否显示标题栏。默认是 yes。 
toolbar=yes|no|1|0 是否显示浏览器的工具栏。默认是 yes。 
top=pixels 窗口的 y 坐标。 
width=pixels 窗口的文档显示区的宽度。以像素计。 

     */
    
    /**
     * 打开一个新的窗口
     * @param parameters
     */
    open : function (url, parameters) {
        if (this.isNotObject(parameters)) {
            return;
        }
        var ps = [];
        for (var p in parameters) {
            ps[ps.length] = p + "=" + parameters[p];
        }
        alert(ps);
    },
    
    openDialog : function (url, width, height, callback) {

        var instance = this;
        
        var w = this.getTopWindow();
        var d = w.document;
        
        var body = d.body;
        var div = d.createElement("DIV");
        var img = d.createElement("IMG");
        var iframe = d.createElement("IFRAME");
        
        var m = new Mask();
        
        this.gradient(div, 1, "#FF0554A3", "#FF96D4FF");
        div.style.backgroundColor = "#0554A3";
        div.style.border = "1px solid #1A306D";
        div.style.position = "absolute";
        div.style.width = this.addUnit(width);
        div.style.height = this.addUnit(height);
        this.center(div);
        
        var s = new Shadow(div);
        
        img.alt = "关闭";
        img.src = this.ctx + "/images/Power/close.gif";
        img.style.cursor = "pointer";
        img.style.position = "absolute";
        img.style.right = "5px";
        img.style.top = "5px";
        img.onclick = function () {
            body.removeChild(div);
            s.remove();
            m.remove();
            if (instance.isFunction(callback)) {
                callback();
            }
        };
        
        iframe.width = "100%";
        iframe.height = instance.addUnit(height - 25);
        iframe.style.marginTop = "25px";
        iframe.frameBorder = "0";
        iframe.src = url;
        
        body.appendChild(div);
        div.appendChild(img);
        div.appendChild(iframe);
    },
    
    /*
     * Usage:
     * openTabs({
     *     title: "Title",
     *     width: 100,
     *     height: 100,
     *     urls: [
     *         {title: "Baidu", url: "htt://www.baidu.com/"},
     *         {title: "Yahoo", url: "http://www.yahoo.cn/"},
     *         {title: "Google", url: "http://www.google.cn/"},
     *         {title: "Xunlei", url: "http://www.xunlei.com/"}
     *     ]
     * });
     */
    openTabs : function (params) {
        
        if (this.isNotObject(params)) {
            return;
        }
        
        var w = window;
        var d = window.document;
        var body = d.body;
        var div = d.createElement("DIV");
        var title = d.createElement("SPAN");
        var close = d.createElement("SPAN");
        var tabsDiv = d.createElement("DIV");
        body.appendChild(div);
        div.appendChild(title);
        div.appendChild(close);
        div.appendChild(tabsDiv);
        
        div.className = "tabs_window";
        div.style.width = this.addUnit(params.width);
        div.style.height = this.addUnit(params.height);
        div.style.position = "absolute";
        this.center(div);
        if (params.moveable) {
            //this.dnd(div);
        }
        
        title.className = "title";
        title.innerHTML = params.title;
        
        close.className = "close";
        close.onclick = function () {
            body.removeChild(div);
        };
        
        var currentTab = null;
        var h = this.addUnit(params.height - 50);
        tabsDiv.className = "tabs";
        for (var i = 0; i < params.urls.length; i++) {
            var tab = d.createElement("SPAN");
            tabsDiv.appendChild(tab);
            if (i === 0) {
                tab.className = "current";
                currentTab = tab;
            }
            tab.innerHTML = params.urls[i].title + '<iframe scrolling="no" frameborder="0" height="' + h + '" src="' + params.urls[i].url + '"></iframe>';
            tab.onclick = function () {
                if (currentTab === this) {
                    return;
                }
                this.className = "current";
                currentTab.className = "";
                currentTab = this;
            };
        }
    },
    
    /*
     * Usage:
     * openSelect({
     *     dom: document.getElementById(),
     *     width: 200,
     *     size: 3,
     *     options: [
     *         {label: '', value: ''},
     *         {label: '', value: ''},
     *         {label: '', value: ''},
     *         {label: '', value: ''}
     *     ]
     * });
     */
    
    openSelect : function (params) {
        
        if (this.isNotObject(params)) {
            return;
        }
        
        var left = params.left;
        var top = params.top;
        if (this.isObject(params.dom)) {
            left = this.getLeft(params.dom);
            top = this.getTop(params.dom);
        }
        
        var w = window;
        var d = window.document;
        var body = d.body;
        var div = d.createElement("DIV");
        var select = d.createElement("SELECT");
        body.appendChild(div);
        div.appendChild(select);
        
        div.className = "div_select";
        div.style.left = this.addUnit(left);
        div.style.top = this.addUnit(top + params.dom.offsetHeight);
        
        select.size = params.size;
        select.style.width = "100%";
        for (var i = 0; i < params.options.length; i++) {
            select.options[i] = new Option(params.options[i].label, params.options[i].value);
        }
        select.onchange = function () {
            params.dom.value = this.value;
            body.removeChild(div);
        }
        
        d.onclick = function () {
            if (window.event.srcElement !== select) {
                body.removeChild(div);
            }
        }
        
    },
    
    /*
     * window.dialogArguments
     * mean: window.showModalDialog(sURL[, vArguments][, sFeatures]) --> vArguments
     * window.returnValue
     * var returnValue = window.showModalDialog(sURL[, vArguments][, sFeatures])
     * Usage:
     * var returnValue = openModalDialog({url: 'http://www.baidu.com/', width: 200, height: 200, args: []});
     * 
     * Notice: IE only
     */
    openModalDialog : function (params) {
        var url = params.url;
        var w = params.width;
        var h = params.height;
        var args = params.args;
        var fs = "dialogWidth=" + w + "px; dialogHeight=" + h + "px; helper=0; status=0; scroll=0";
        return window.showModalDialog(url, args, fs);
    },
    
    /*
     * Others
     */
    
    gradient : function (e, t, sc, ec) {
        if (this.isNotIE() || this.isNotObject(e)) {
            return;
        }
        e.style.filter = "progid:DXImageTransform.Microsoft.Gradient("
            + "gradientType=" + t + ", "
            + "startColorStr='" + sc + "', "
            + "endColorStr='" + ec + "')";
    },
    
    getElement : function (id, w) {
        if (this.isNotString(id)) {
            return null;
        }
        var d = document;
        if (w && w.document) {
            d = w.document;
        }
        return d.getElementById(id);
    },
    
    getTopWindow : function () {
        var w = window.top;
        if (w.document.getElementsByTagName("body").length < 1) {
            w = window;
        }
        return w;
    },
    
    addUnit : function (n, u) {
        if (this.isNotNumber(n)) {
            return "";
        }
        return n + (this.isString(u) ? u : "px");
    },
    
    /**
     * 以渐变的形式隐藏元素
     * @param: element 将被隐藏的元素
     * @param: delay 延时毫秒数, 总延时 = delay * 50
     * @param: callback 回调函数, 可选
     */
    hideGradually : function (e, delay, callback) {
        if (this.isNotIE() || this.isNotObject(e)) {
            return;
        }
        
        var instance = this;
        
        if (!e.filters.alpha) {
            e.style.filter = "alpha(opacity=100)";
        }
        
        var interval = window.setInterval(function () {
            if (e.filters.alpha.opacity > 0) {
                e.filters.alpha.opacity -= 2;
            } else {
                e.style.display = "none";
                
                window.clearInterval(interval);
                interval = null;
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, delay ? delay : 20);
        
        return interval;
    },

    /**
     * 以渐变的形式显示元素
     * @param: element 将被显示的元素
     * @param: delay 延时毫秒数, 总延时 = delay * 50
     * @param: callback 回调函数, 可选
     */
    showGradually : function (e, delay, callback) {
        if (this.isNotIE() || this.isNotObject(e)) {
            return;
        }
        
        var instance = this;
        
        if (!e.filters.alpha) {
            e.style.filter = "alpha(opacity=0)";
        }
        
        if ("none" === e.style.display) {
            e.style.display = "";
        }
        
        var interval = window.setInterval(function () {
            if (e.filters.alpha.opacity < 100) {
                e.filters.alpha.opacity += 2;
            } else {
                window.clearInterval(interval);
                interval = null;
                if (instance.isFunction(callback)) {
                    callback();
                }
            }
        }, delay ? delay : 20);
        
        return interval;
    },
    
    flashNews : function (imgInfo, width, height, textHeight) {
        
        // pics, links, texts: flash的内容参数(关键点)
        // imgUrl: flash图片的路径, imgText: 图片的描述文字, imgLink: 图片和文字的链接地址
        var pics = "";
        var texts = "";
        var links = "";
        for (var i = 0; i < imgInfo.length; i++) {
            pics += (i === 0 ? "" : "|") + imgInfo[i].imgUrl;
            texts += (i === 0 ? "" : "|") + imgInfo[i].imgText;
            links += (i === 0 ? "" : "|") + imgInfo[i].imgLink;
        }

        var swfHeight = height + textHeight;
        
        // flash的界面参数(外观)
        var flashVars = "pics=" + pics + "&texts=" + texts + "&links=" + links + "&borderwidth=" + width + "&borderheight=" + height + "&textheight=" + textHeight;
        var flash = "" +
            "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n" +
            "    codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"\n" +
            "    width=\"" + width + "\" height=\"" + swfHeight + "\">\n" +
            "    <param name=\"allowScriptAccess\" value=\"sameDomain\">\n" +
            "    <param name=\"movie\" value=\"pixviewer.swf\">\n" +
            "    <param name=\"quality\" value=\"high\">\n" +
            "    <param name=\"bgcolor\" value=\"#E3E3E3\">\n" +
            "    <param name=\"menu\" value=\"false\">\n" +
            "    <param name=\"wmode\" value=\"transparent\">\n" +
            "    <param name=\"FlashVars\" value=\"" + flashVars + "\">\n" +
            "    <embed src=\"pixviewer.swf\" wmode=\"transparent\" FlashVars=\"" + flashVars + "\" \n" +
            "        menu=\"false\" bgcolor=\"#E3E3E3\" quality=\"high\" \n" +
            "        width=\"" + width + "\" height=\"" + height + "\" \n" +
            "        allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" \n" +
            "        pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n" +
            "</object>";
        
        document.write(flash);
    },
    
    /**
     * 创建消息框
     * @param: message 要显示的消息
     * @param: type 消息的类型 ERROR, INFO, QUESTION, WARNING 可选
     * @param: position 消息框的位置 C, TL, TR, BL, BR 可选
     */
    showMsg : function (message, type, position) {
        
        var instance = this;
        var topWin = this.getTopWindow();
        var d = topWin.document;// 最顶层窗口的document对象
        var body = d.body;// 最顶层窗口的document的body对象
        var w = d.documentElement.clientWidth;// 当前窗口的可见的宽度
        var h = d.documentElement.clientHeight;// 当前窗口的可见的高度
        var desl = d.documentElement.scrollLeft;
        var dest = d.documentElement.scrollTop;
        
        var msgDiv = d.createElement("TABLE");
        var img = d.createElement("IMG");
        var msgNode = d.createTextNode(message);
        
        var tr = msgDiv.insertRow();
        var td = tr.insertCell();
        
        var mstyle = msgDiv.style;
        
        body.appendChild(msgDiv);
        td.appendChild(img);
        td.appendChild(msgNode);
        
        // 图片类型: ERROR, INFO, QUESTION, WARNING
        var image = "icon-info.gif";
        switch (type) {
            case "ERROR":
                image = "icon-error.gif";
                break;
            case "INFO":
                image = "icon-info.gif";
                break;
            case "QUESTION":
                image = "icon-question.gif";
                break;
            case "WARNING":
                image = "icon-warning.gif";
                break;
        }

        img.src = this.ctx + "/images/Power/" + image;
        img.style.styleFloat = "left";
        
        // 样式处理
        mstyle.position = "absolute";
        mstyle.fontSize = "12px";
        mstyle.border = "1px solid #6FA1D9";
        mstyle.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FFCBDFF7')";
        mstyle.backgroundColor = "#CBDFF7";
        
        //td.align = "center";
        td.valign = "middle";
        td.style.wordBreak = "break-all";
        td.style.padding = "10px";
        
        // 位置处理
        mstyle.width = "300px";
        mstyle.height = "100px";
        switch (position) {
            case "C":
                mstyle.left = ((w - parseInt(mstyle.width)) / 2) + desl + "px";
                mstyle.top = ((h - parseInt(mstyle.height)) / 2) + dest + "px";
                break;
            case "TL":
                mstyle.left = "0";
                mstyle.top = "0";
                break;
            case "TR":
                mstyle.right = "0";
                mstyle.top = "0";
                break;
            case "BL":
                mstyle.left = "0";
                mstyle.bottom = "0";
                break;
            case "BR":
                mstyle.left = this.addUnit(w - parseInt(mstyle.width) + desl);
                mstyle.top = this.addUnit(h - parseInt(mstyle.height) + dest);
                break;
            default:
                mstyle.left = this.addUnit(w - parseInt(mstyle.width) + desl);
                mstyle.top = this.addUnit(h - parseInt(mstyle.height) + dest);
                break;
        }
        
        instance.zoomIn(msgDiv);
        
        // 事件处理
        topWin.setTimeout(function () {
            instance.zoomOut(msgDiv, function () {
                body.removeChild(msgDiv);
                msgDiv = null;
            });
        }, 3000);
        
        topWin.onunload = function () {
            if (msgDiv) {
                body.removeChild(msgDiv);
                msgDiv = null;
            }
        };
    },
    
    /**
     * 功能类似于window.alert(msg)
     * @param msg 要显示的信息
     * @param callback 回调方法, 即点击确定按钮后执行的方法, 可选
     */
    alert : function (msg, callback) {
        
        var instance = this;
        var d = this.getTopWindow().document;
        var body = d.body;
        
        var m = new Mask();
        
        var table = d.createElement("TABLE");
        var tr1 = table.insertRow();
        var tr2 = table.insertRow();
        var td1 = tr1.insertCell();
        var td2 = tr2.insertCell();
        var button = d.createElement("BUTTON");
        
        body.appendChild(table);
        td2.appendChild(button);
        
        table.style.position = "absolute";
        table.style.width = "300px";
        table.style.height = "100px";
        table.style.border = "1 solid #6FA1D9";
        table.style.padding = "5px";
        table.style.fontSize = "12px";
        table.style.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FFCBDFF7')";
        instance.center(table);
        
        tr1.height = "80px";
        tr2.height = "20px";
        
        td1.align = "center";
        td1.valign = "middle";
        td1.style.wordBreak = "break-all";
        td1.style.padding = "10px";
        td1.innerText = msg ? msg : "";
        
        td2.align = "center";
        td2.valign = "middle";
        td2.style.paddingBottom = "5px";
        
        button.innerText = "确定";
        button.style.border = "1px solid #6FA1D9";
        button.style.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FF6FA1D9')";
        
        button.onclick = function () {
            body.removeChild(table);
            m.remove();
            table = null;
            m = null;
            if (instance.isFunction(callback)) {
                callback();
            }
        };
        
        button.focus();
    },
    
    /**
     * 功能类似于window.confirm(msg)
     * @param msg 要显示的信息
     * @param callback 回调方法, 即点击确定按钮后执行的方法, 可选
     */
    confirm : function (msg, callback) {
        
        var instance = this;
        var d = this.getTopWindow().document;
        var body = d.body;
        
        var m = new Mask();
        
        var table = d.createElement("TABLE");
        var tr1 = table.insertRow();
        var tr2 = table.insertRow();
        var td1 = tr1.insertCell();
        var td2 = tr2.insertCell();
        var button1 = d.createElement("BUTTON");
        var button2 = d.createElement("BUTTON");
        var textNode = document.createTextNode(" ");
        
        body.appendChild(table);
        td2.appendChild(button1);
        td2.appendChild(textNode);
        td2.appendChild(button2);
        
        table.style.position = "absolute";
        table.style.width = "300px";
        table.style.height = "100px";
        table.style.border = "1px solid #6FA1D9";
        table.style.padding = "5px";
        table.style.fontSize = "12px";
        table.style.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FFCBDFF7')";
        instance.center(table);
        
        tr1.height = "80px";
        tr2.height = "20px";
        
        td1.align = "center";
        td1.valign = "middle";
        td1.style.wordBreak = "break-all";
        td1.style.padding = "10px";
        td1.innerText = msg ? msg : "";
        
        td2.align = "center";
        td2.valign = "middle";
        td2.style.paddingBottom = "5px";
        
        button1.innerText = "确定";
        button1.style.border = "1px solid #6FA1D9";
        button1.style.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FF6FA1D9')";
        
        button2.innerText = "取消";
        button2.style.border = "1px solid #6FA1D9";
        button2.style.filter = "progid:DXImageTransform.Microsoft.Gradient(enabled='true', gradientType=0, startColorStr='#FFFFFFFF', endColorStr='#FF6FA1D9')";
        
        button1.onclick = function () {
            body.removeChild(table);
            m.remove();
            table = null;
            m = null;
            if (instance.isFunction(callback)) {
                callback();
            }
        };
        
        button2.onclick = function () {
            body.removeChild(table);
            m.remove();
            table = null;
            m = null;
        };
        
        button2.focus();
    }
};

function IE() {}
IE.prototype = new Common();

function FF() {}
FF.prototype = new Common();
FF.prototype.dnd = function (dom) {
    
};

var Power = new Common();


/**
 * Object Shadow()
 * @constructor
 * @class Shadow
 */
function Shadow(e) {
    var _c = new Common();
    var l = e.style.left ? parseInt(e.style.left) + 8 : 8;
    var t = e.style.top ? parseInt(e.style.top) + 8 : 8;
    var w = e.style.width ? parseInt(e.style.width) : e.clientWidth;
    var h = e.style.height ? parseInt(e.style.height) : e.clientHeight;
    var d = e.ownerDocument;
    var body = d.body;
    var shadow = d.createElement("DIV");
    body.appendChild(shadow);
    
    shadow.className = Style.shadowDiv;
    shadow.style.background = "black";
    shadow.style.width = _c.addUnit(w);
    shadow.style.height = _c.addUnit(h);
    _c.moveTo(shadow, {x: l, y: t});
    
    this.remove = function () {
        body.removeChild(shadow);
    };
}

/**
 * Object Scrolling()
 * @constructor
 * @class Scrolling
 */
function Scrolling(w) {
    
    var body = w.document.body;
    var html = body.parentNode;
    while ("HTML" !== html.nodeName && html.parentNode) {
        html = html.parentNode;
    }
    var h_of = html.style.overflow;
    var b_of = body.style.overflow;
    
    this.enable = function () {
        html.style.overflow = h_of;
        body.style.overflow = b_of;
    };
    
    this.disable = function () {
        h_of = html.style.overflow;
        b_of = body.style.overflow;
        html.style.overflow = "hidden";
        body.style.overflow = "hidden";
    };
}

/**
 * Object Mask()
 * @constructor
 * @class Mask
 */
function Mask(color) {

    var _c = new Common();
    var w = window.top;
    if (w.document.getElementsByTagName("body").length < 1) {
        w = window;
    }
    var d = w.document;
    var desw = d.documentElement.scrollWidth;
    var desh = d.documentElement.scrollHeight;
    var body = d.body;
    var maskIframe = d.createElement("IFRAME");
    var maskDiv = d.createElement("DIV");
    body.appendChild(maskIframe);
    body.appendChild(maskDiv);

    maskIframe.className = Style.maskIframe;
    maskIframe.style.width = _c.addUnit(desw > screen.width ? desw : screen.width);
    maskIframe.style.height = _c.addUnit(desh > screen.height ? desh : screen.height);
    
    maskDiv.className = Style.maskDiv;
    maskDiv.style.backgroundColor = _c.isString(color) ? color : "gray";
    maskDiv.style.width = _c.addUnit(desw > screen.width ? desw : screen.width);
    maskDiv.style.height = _c.addUnit(desh > screen.height ? desh : screen.height);
    
    var scrolling = new Scrolling(w);
    scrolling.disable();
    
    this.remove = function() {
        body.removeChild(maskDiv);
        body.removeChild(maskIframe);
        scrolling.enable();
    };
}

/**
 * Object WaitingMask()
 * @constructor
 * @class WaitingMask
 */
function WaitingMask() {
    
    var _c = new Common();
    var m = new Mask();
    
    var w = _c.getTopWindow();
    var d = w.document;
    var body = d.body;
    var div = d.createElement("DIV");
    body.appendChild(div);
    
    div.className = Style.maskWaiting;
    _c.center(div);
    
    this.remove = function () {
        body.removeChild(div);
        m.remove();
    };
}

/**
 * Object Style()
 * @constructor
 * @class Style
 */
function Style() {}
Style.maskDiv = "mask-div";
Style.maskIframe = "mask-iframe";
Style.maskWaiting = "mask-waiting";
Style.shadowDiv = "shadow-div";


function Browser() {}
Browser.IE = 1;
Browser.FF = 2;

//========================================================================================
//========================================================================================


/**
 * document.getElementById()
 * @param id 字符串
 * @return Object
 */
function $E(id, w) {
    if (!id || "string" !== typeof id) {
        window.alert("参数id不是字符串：$E(id)");
        return null;
    }
    var d = (w && w.document) ? w.document : document;
    return d.getElementById(id);
}
